package com.waya.web.browser.js_interface;

import android.webkit.JavascriptInterface;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Created by JesseHev on 2017/12/5.
 * describe: 校验obj是否有js回调方法
 */

public abstract class AbsIJSInterface implements IJSInterface {

  @Override public boolean checkObject(Object obj) {
    boolean javaInterface = false;
    Class clazz = obj.getClass();
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
      Annotation[] annotations = m.getAnnotations();
      for (Annotation att : annotations) {
        if (att instanceof JavascriptInterface) {
          javaInterface = true;
          break;
        }
      }
      if (javaInterface) {
        break;
      }
    }
    return javaInterface;
  }
}
